package Text3;

import java.util.*;

public class Main {
    static int N = 510;
    static int[][] a = new int[N][N];
    static int[][] f = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                a[i][j] = in.nextInt();
            }
        }
        for (int i = 1; i <= n; i++) {
            f[n][i] = a[n][i];
        }
        for (int i = n - 1; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                f[i][j] = Math.max(f[i + 1][j], f[i + 1][j + 1]) + a[i][j];
            }
        }
        System.out.println(f[1][1]);
    }
}

